﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using C.Entities;
using C.Unite;
using ChanExt;

namespace ArtLand.OA.Project.SystemMgr
{
    public partial class SysChangePwd : CommonPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnClose.OnClientClick = ActiveWindow.GetHideReference();
            }
        }
         

        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            bool bl = true;
            string errortitle = "";
            if (txt_NewPwd.Text != txt_NewPwd2.Text)
            {
                bl = false;
                errortitle = "两次密码输入不一致！";
            }
            if (bl)
            {
                Sys_Users sys_u = TbsDbSession.Default.From<Sys_Users>().Where(Sys_Users._.UserID == CookInfo.EAdminid()).ToFirst();

                if (sys_u != null)
                {
                    if (sys_u.Pwd == StringHelper.md5(txt_OldPwd.Text, 16))
                    {
                        Sys_Users tea = new Sys_Users();
                        tea.UserID = CookInfo.EAdminid();
                        tea.Attach();
                        tea.Pwd = StringHelper.md5(txt_NewPwd.Text, 16);
                        TbsDbSession.Default.Update<Sys_Users>(tea);
                        Alert.ShowInTop("修改密码成功！");
                        PageContext.RegisterStartupScript(ActiveWindow.GetHideReference());
                    }
                    else
                    {
                        Alert.Show("输入的原密码不正确！");
                    }
                }
                else
                {
                    Alert.Show("帐号异常");
                }
                //}
                //else
                //{
                //    Alert.ShowInTop("输入的原密码不正确！");
                //}
            }
            else
            {
                Alert.ShowInTop(errortitle);
            }
        }

    }
}